// shopPages/orderSuccess/orderSuccess.js


import {
  update_user_status,
  get_carte
} from "../../utils/api.js";
var app = getApp();
var page = 1;
var new_list= [];
var more_status = true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    integralShow:false,
    price:0,
    reIntegral:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    page = 1;
    new_list = [];
    // that.getMyIntegral();
    that.IntegralGoods();
    var integral_amount = 0;
    var integralShow = true;
    if (options.integrals != undefined){
      var integrals = JSON.parse(options.integrals);
      
      for(var i in integrals){
        integral_amount = parseFloat(integral_amount)+parseFloat(integrals[i].integral_price)
      }
    } else if (options.integral != undefined){
      var integral = JSON.parse(options.integral);
      
      integral_amount = parseFloat(integral_amount) + parseFloat(integral)
      
    }
    
    if (integral_amount>0){
      integralShow=false;
    }else{
      var mount = parseFloat(options.price) - parseFloat(options.freight_free)
      that.getReIntegral(mount);
    }

    that.setData({
      integralShow: integralShow,
      price: options.price,
    });
  },
  getMyIntegral:function(){
    const that = this
    const uid = app.globalData.userInfo.id
    // const uid = 191
    app.HttpGetSend(
      '/user_api/getField', {
        uid: uid,
        fields: 'integral'
      },
      function (res) {
        that.setData({
          myIntegral: res.data.integral
        });
        
      })
  },
  IntegralGoods:function(){
    const that = this
    app.HttpGetSend(
      '/order_api/success_page', {
        pageno:page
      },
      function (res) {
        wx.hideLoading();
        var list = res.data;
        if (list.length < 10) {
          more_status = false;
        } else {
          more_status = true;
          page += 1;
         
        }
        console.log(more_status);
        for (let i = 0; i < list.length; i++) {
          new_list.push(list[i]);
        }


        that.setData({
          goodslist: new_list
        });

      })
  },
  getReIntegral: function (price){
    price = parseFloat(price)*parseFloat(100);

    var integral = 0;
    if (0 <= price && price < 50000) {
      integral = Math.round(price / 2);
    } else if(50000 <= price && price < 200000){
      integral = Math.round((price * 2) / 3);
    } else if(200000 <= price && price < 500000){
      integral = Math.round((price * 3) / 4);
    } else if(price >= 500000){
      integral = 400000;
    }else{
      integral = 0;
    }
    this.setData({
      reIntegral: integral/100
    });
  },
  showIntegral:function(){
    wx.redirectTo({
      url: '/shopPages/integrals_shop/integrals_shop',
    })
  },
  toGoodsDetail_: function (e) {
    wx.navigateTo({
      url: "/pages/goodsDetail/goodsDetail?id=" + e.currentTarget.dataset.id
    })
  },
  bindGoodsTap: function (e) {
    var id = e.currentTarget.dataset.button_typid;
    var title = e.currentTarget.dataset.button_status;
    wx.navigateTo({
      url: '/pages/goodsDetail/goodsDetail?id=' + id + '&title=' + title,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (more_status == true) {
      var that = this;
      // 显示加载图标
      wx.showLoading({
        title: '玩命加载中',
      })
      // 页数+1
      that.IntegralGoods();

    } else {
      wx.hideLoading();
    }
  },

  /**
   * 用户点击右上角分享
   */

})